import Vue from 'vue'
import Router from 'vue-router'
const _import = require('./_import_' + process.env.NODE_ENV)
// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'

/** note: submenu only apppear when children.length>=1
*   detail see  https://panjiachen.github.io/vue-element-admin-site/#/router-and-nav?id=sidebar
**/

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirct in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    roles: ['admin','editor']     will control the page roles (you can set multiple roles)
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
    noCache: true                if fasle ,the page will no be cached(default is false)
  }
**/
export const constantRouterMap = [
  { path: '/login', component: _import('login/index'), hidden: true },
  { path: '/404', component: _import('error/404'), hidden: true },
  { path: '/401', component: _import('error/401'), hidden: true },
  {
    path: '',
    component: Layout,
    redirect: 'dashboard',
    children: [{
      path: 'dashboard',
      component: _import('dashboard/index'),
      name: 'dashboard',
      meta: { title: '首页', icon: 'dashboard', noCache: true }
    }]
  }
]

export default new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

export const asyncRouterMap = [
  {
    path: '/user',
    component: Layout,
    redirect: 'noredirect',
    name: 'userManage',
    meta: {
      perm: 'm:userManage',
      title: '用户管理',
      icon: 'chart'
    },
    children: [
      { path: 'user', component: _import('user/user'), name: 'user', meta: { perm: 'm:userManage:user', title: '会员管理', noCache: true }},
      { path: 'address', component: _import('user/address'), name: 'address', meta: { perm: 'm:userManage:address', title: '收货地址', noCache: true }},
      { path: 'collect', component: _import('user/collect'), name: 'collect', meta: { perm: 'm:userManage:collect', title: '会员收藏', noCache: true }},
      { path: 'footprint', component: _import('user/footprint'), name: 'footprint', meta: { perm: 'm:userManage:footprint', title: '会员足迹', noCache: true }},
      { path: 'history', component: _import('user/history'), name: 'history', meta: { perm: 'm:userManage:history', title: '搜索历史', noCache: true }}
    ]
  },

  {
    path: '/sys',
    component: Layout,
    redirect: 'noredirect',
    name: 'sysManage',
    meta: {
      perm: 'm:sysManage',
      title: '系统管理',
      icon: 'chart'
    },
    children: [
      { path: 'admin', component: _import('sys/admin'), name: 'admin', meta: { perm: 'm:sysManage:admin', title: '用户管理', noCache: true }},
      { path: 'role', component: _import('sys/role'), name: 'roleManage', meta: { perm: 'm:sysManage:role', title: '角色管理', noCache: true }},
      { path: 'permission', component: _import('sys/permission'), name: 'permission', meta: { perm: 'm:sysManage:permission', title: '权限管理', noCache: true }},
      {
        hidden: true,
        path: 'role_manage/:roleId/assign_perm',
        name: 'role_manage_assign_perm',
        component: _import('sys/assign_perm'),
        meta: {
          hiddenTag: true,
          title: '角色授权'
        }
      }
      // { path: 'config', component: _import('sys/config'), name: 'config', meta: { perm: 'm:sysManage:config', title: '系统配置', noCache: true } }
      // { path: 'os', component: _import('sys/os'), name: 'os', meta: { title: '对象存储', noCache: true }}
    ]
  },

  {
    path: '/stat',
    component: Layout,
    redirect: 'noredirect',
    name: 'statManage',
    meta: {
      perm: 'm:statManage',
      title: '统计',
      icon: 'chart'
    }
    // children: [
    //   { path: 'user', component: _import('stat/user'), name: 'statUser', meta: { perm: 'm:statManage:statUser', title: '用户统计', noCache: true } },
    //   { path: 'order', component: _import('stat/order'), name: 'statOrder', meta: { perm: 'm:statManage:statOrder', title: '订单统计', noCache: true } },
    //   { path: 'goods', component: _import('stat/goods'), name: 'statGoods', meta: { perm: 'm:statManage:statGoods', title: '商品统计', noCache: true } },
    //   { path: 'integral', component: _import('stat/integral'), name: 'statIntegral', meta: { perm: 'm:statManage:statIntegral', title: '积分统计', noCache: true } },
    //   { path: 'report', component: _import('stat/report'), name: 'statreport', meta: { perm: 'm:statManage:statReport', title: '综合查询', noCache: true } }
    // ]
  },

  { path: '*', redirect: '/404', hidden: true }
]
